﻿@Imports System.Data
@Imports CalibreVB
@Code
    PageData("Title") = ConfigurationManager.AppSettings("SiteTitle").ToString
    Layout = "~/_SiteLayout.vbhtml"
    
    Dim _CatRoot() As String = ConfigurationManager.AppSettings("CatRoot").ToString.Split(",")
    Dim _bgcolor() As String = ConfigurationManager.AppSettings("bgcolor").ToString.Split(",")
    Dim _sql_str_where() As String = sql_str_Class.Get_sql_str_where
    Dim _sql_str_section() As String = sql_str_Class.Get_sql_str_section

    Dim SiteMapTable = SiteMapBLL.GetListForSiteMap("calibrevb", "en")
    Dim LabelSection As String = ""

    Dim numberOfRecords As Int32 = 0
    Dim _cat = UrlData(0).ToString()

    Dim sql_str_key As String = ""
    Dim sql_str_count As String = ""
    Dim itemindex As Int32 = Array.IndexOf(_CatRoot, _cat)
    
    Dim SectionTable As DataTable
    Dim RowsFound() As DataRow
    Dim SectionRow As DataRow()
    
    
    If _cat = "usercat" Then
        Dim _id = UrlData(1).AsInt()

        Dim filter As String = String.Format("[ID] = {0}", _id)

        Dim SectionName() As Data.DataRow
        SectionName = SiteMapTable.Select(filter)
        LabelSection = SectionName(0)(1).ToString.ToLower
        filter = String.Format("[Parent] = {0}", _id)
        SectionRow = SiteMapTable.Select(filter)
        If SectionRow.Length > 0 Then
            SectionTable = SectionRow.CopyToDataTable()
        Else
            SectionTable = SiteMapTable
        End If
    Else
        SectionTable = LibCalibreVB.GetDataTable(_sql_str_section(itemindex))
        sql_str_count = "SELECT COUNT(books.id) AS Expr1 FROM books " & _sql_str_where(itemindex)
    End If
                    
    Dim f As String = UrlData(1)
    
    If IsNumeric(f) Then
        f = ""
    End If

    numberOfRecords = SectionTable.Select().Length
    Dim url As String = "/List/" & _cat

    If f = "" Or _cat = "usercat" Then
        RowsFound = SectionTable.Select()
    Else
        RowsFound = SectionTable.Select("SUBSTRING(str_key, 1, 1) = '" & f & "'")
        LabelSection = _cat & " :: " & f
    End If

    _cat = _cat.ToLower
    LabelSection = _cat

End Code

<div class="container">
    <div class="row">
        <div class="metro span12">
        <h2>@LabelSection</h2>
            @If _cat = "" Then
                @CalibreHelpers.FormatHome(SiteMapTable, _CatRoot, _bgcolor)
            Else
                If numberOfRecords < ConfigurationManager.AppSettings("CatSize") Or f <> "" Or _cat = "usercat" Then
                    @CalibreHelpers.FormatSection(_cat, RowsFound, itemindex, _CatRoot, _bgcolor, sql_str_count)
                Else
                    @CalibreHelpers.FormatSectionAlpha(_cat, SectionTable)
                End If
            End If
        </div>
    </div>
</div>
